﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Resources;

namespace BasharLulu.QuranBookmark.WP7
{
    public class HistoryItem : INotifyPropertyChanged
    {
        private int _SuraKey;
        public int SuraKey
        {
            get
            {
                return _SuraKey;
            }
            set
            {
                if (value != _SuraKey)
                {
                    _SuraKey = value;
                    NotifyPropertyChanged("SuraKey");
                }
            }
        }

        private int _AyaKey;
        public int AyaKey
        {
            get
            {
                return _AyaKey;
            }
            set
            {
                if (value != _AyaKey)
                {
                    _AyaKey = value;
                    NotifyPropertyChanged("AyaKey");
                }
            }
        }

        private DateTime _BookmarkDateTime;
        public DateTime BookmarkDateTime
        {
            get
            {
                return _BookmarkDateTime;
            }
            set
            {
                if (value != _BookmarkDateTime)
                {
                    _BookmarkDateTime = value;
                    NotifyPropertyChanged("BookmarkDateTime");
                }
            }
        }

        public string EnglishName
        {
            get
            {
                string toReturn = string.Empty;

                if (App.SuraViewModel.Items.Count == 0)
                    App.SuraViewModel.LoadData();

                var xxx = from sura in App.SuraViewModel.Items
                          where sura.SuraNumber == this._SuraKey
                          select sura;

                SuraViewModel item = xxx.FirstOrDefault();

                if (item != null)
                    toReturn = string.Format("{0}", item.SuraEnglishName, item.SuraNumber);

                return toReturn;
            }
        }

        public string ArabicName
        {
            get
            {
                string toReturn = string.Empty;

                if (App.SuraViewModel.Items.Count == 0)
                    App.SuraViewModel.LoadData();

                var xxx = from sura in App.SuraViewModel.Items
                          where sura.SuraNumber == this._SuraKey
                          select sura;

                SuraViewModel item = xxx.FirstOrDefault();

                if (item != null)
                    toReturn = string.Format("{0}", item.SuraArabicName, item.SuraNumber);

                return toReturn;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
